Repository navigation
fix(web): collapse a first child's top margin through its block; stop counting ::marker as an element - #851
Merged
Conversation
… counting ::marker as an element CSS 2.2 §8.3.1 leading half. Round 6 closed the trailing half with LayoutResult.trailing_margin_b, which works because the margin is known after the children are laid out. The leading half cannot use that shape: the caller advances cy by collapse_margins_signed(prev_margin_b, cst.margin_t) BEFORE layout_with_style runs. Resolved with the two-phase mechanics offset_layout_subtree already serves elsewhere rather than a pre-pass: the block child is placed from its DECLARED margin-top, then its subtree is re-offset by the difference against its EFFECTIVE one, collapse(declared, child.leading_margin_t). When the block itself collapses its top through, the whole effective margin is pulled back out, the height shrinks by it, and it is returned as this block's leading_margin_t for its own parent — so N nested wrappers yield ONE margin, not one per level. The <body> hand-rolled case in the same loop now uses the effective margin too. block_top_margin_collapses_through mirrors the bottom half's exclusion set exactly, height clamps included: CSS lets a top margin escape a fixed-height block, but admitting that here would move boxes the trailing half still holds, so it stays conservative and the remaining case is recorded. Chrome oracle, heights: <div><p>t</p></div> 24 (was 40), padding-bottom:10px 50 (was 66), border-bottom:2px 42 (was 58). Second, unrelated-looking but the same family: _simple_web_layout_element did not skip ::marker, which the foundation pass synthesises as every <li>'s FIRST child. The geometry differ stopped counting marker boxes on 2026-09-12; the renderer's own copy of the scheme did not, while the Chrome walker's comment claims the two mirror each other byte-for-byte. Every hit-test and CSS-animation target key inside a list item was off by one ordinal. All three copies now exclude ::-prefixed tags. Specs (the two per .claude/rules/testing.md): - test/01_unit/browser_engine/first_child_top_margin_collapse_spec.spl, 10 AC — 3 reproducing, 7 generalizing, including a <li> (whose ::marker is its first node, so a loop that counted it could never let the real first child escape) and an out-of-flow first child. - test/01_unit/browser_engine/li_marker_nth_path_key_spec.spl, 3 AC. Sabotage: forcing the predicate false fails AC-1/2/3/8 and leaves AC-4..7 green; swapping "::" for a prefix no tag starts with fails AC-1/2 and leaves AC-3 green. li_last_child_margin_collapse_spec stays 12/12. Measured in ONE worktree with ONE binary per .claude/rules/testing.md (before = the same tree with only the two lib files at HEAD~1): geometry differ css-layout 376/359 and animation 81/79, identical on both sides — the predicate excludes flex/grid items and padded/bordered parents, which is what those demo pages are made of. The pixel differ could not run on this macOS host (Chrome hits its 90s screenshot alarm on every page; one html Simple render had not finished after 20 minutes, in BOTH lib states), so the brief's pixel stop criterion is unevaluable this round and is not claimed either way. Not fixed, recorded: bold advances (no static bold sans exists in-tree; the Linux fallback paths do not exist on macOS), the <li>-reparented geometry desync (narrowed by one step, root NOT established, two candidates named), and tables. ifc_linebox_spec is 0/10 both before and after — pre-existing. Test-tree divergence: check-test-tree-divergence-delta.shs origin/main..HEAD reports PASS — 3213 pre-existing offender(s), 0 introduced by this range. The base verdict is itself FAIL (3941 diverged vs 965 baselined, 3079 new, 103 fixed-but-still-baselined, 32 mirror-only) and is pre-existing, left by other sessions; the offender list was saved by the helper to /var/folders/94/j3lc49d93bx148gqls5kx5d40000gn/T//test_tree_divergence_preexisting.txt and is recorded here as the guard's scoped-delta escape requires. This range adds two specs under test/01_unit/browser_engine/ with no twin in test/unit/, which the delta's own offender-list diff confirms introduces no new divergence. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TVraTPgGDVypESTsVqXPgi
ormastes
temporarily deployed
to
self-review-admission
September 13, 2026 08:30 — with
GitHub Actions
Inactive
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Chrome-parity round 7 for the pure-Simple web renderer. Two layout/keying
defects closed, each with a sabotage-proven spec; two items re-confirmed
blocked and recorded rather than worked around.
1. First-child TOP margin collapse-through (CSS 2.2 §8.3.1, leading half)
Round 6 closed the trailing half (
LayoutResult.trailing_margin_b). Theleading half could not use the same shape: the caller advances
cybycollapse_margins_signed(prev_margin_b, cst.margin_t)beforelayout_with_styleruns, so the first child's effective top margin is unknownwhen the parent's origin is fixed.
Resolved with the two-phase mechanics
offset_layout_subtreealready serveselsewhere, not with a pre-pass: the child is placed from its declared
margin-top, then the child subtree is re-offset by the difference against its
effective one (
collapse(declared, child.leading_margin_t)). When the blockitself collapses its top through, the whole effective margin is pulled back out,
the height shrinks by it, and it is returned as this block's
leading_margin_tfor its own parent — so N nested wrappers yield ONE margin, not one per level.
block_top_margin_collapses_throughmirrors the bottom half's exclusion setexactly (documents, non-block display, out-of-flow, floats, BFC roots, widget
panels, flex/grid items, and conservatively every height clamp).
Chrome oracle, heights in px:
<div><p>t</p></div>24 (was 40),padding-bottom:10px50 (was 66),border-bottom:2px42 (was 58); the casesthat must NOT collapse (top padding,
overflow:hidden, explicit height) areunchanged.
2.
::markercounted as a DOM element in the renderer's nth-path keysThe geometry differ stopped counting
::markerboxes on 2026-09-12. Therenderer's own copy of the same scheme,
_simple_web_layout_element, did not —while the Chrome walker's comment claims the two mirror each other
"byte-for-byte". Since the marker is every
<li>'s FIRST child by construction,every hit-test and CSS-animation target key inside a list item was off by one
ordinal, i.e. addressed the wrong node. All three copies now exclude
::-prefixed tags.Specs (both required by
.claude/rules/testing.md)test/01_unit/browser_engine/first_child_top_margin_collapse_spec.spl— 10 AC:3 reproducing the oracle rows, 7 generalizing (non-collapsing cases, the
escaped margin still separating the block, double nesting, a
<li>whose::markeris its first node, an out-of-flow first child).test/01_unit/browser_engine/li_marker_nth_path_key_spec.spl— 3 AC on thetarget-key scheme.
Sabotage triples recorded in the bug files: forcing
block_top_margin_collapses_throughfalse fails AC-1/2/3/8 and leaves AC-4..7green; swapping the
"::"prefix for one no tag starts with fails AC-1/2 andleaves AC-3 green.
Measurement
Geometry differ,
GEOM_DIFF_HEIGHT=20000, both sides run in the sameworktree with the same binary (
.claude/rules/testing.md§ Measurementtraps — the before side is the same tree with only the two lib files checked
out at
HEAD~1):No movement on either page, and
css-layout.geometry_diff.mdis byte-identicalbetween the runs. That is a real result rather than a failed measurement: the
collapse-through predicate excludes flex/grid items and any parent with top
padding or a border, which is what these card-based demo pages are built from.
The fixes are pinned by the oracle-backed specs, not by these pages.
The PIXEL differ could not be used on this macOS host: Chrome hits the 90 s
screenshot alarm on every page and one
htmlSimple render had not finishedafter 20 minutes, in both lib states. Stated rather than substituted with
numbers measured elsewhere.
Not fixed, recorded
assets/fontsholds one static boldface tree-wide (a blackletter display face) and the sans candidate list is
otherwise variable fonts plus Linux paths absent on macOS. Adding the weight
argument first would change no advance.
<li>reparented under<section>, which is what actually desyncs thegeometry report on
html; narrowed by one step (the emitter copiesnodes[i].parent, so it does not invent the parent) but the root is NOTestablished — two candidates named in the record.
table_layout_spec0/7) — untouched, multi-hour.ifc_linebox_specis 0/10 and fails identically with the two lib filesreverted: pre-existing, not caused here.
🤖 Generated with Claude Code
https://claude.ai/code/session_01TVraTPgGDVypESTsVqXPgi